package com.qf.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @version v1.0.0
 * @Description:
 * @author: 姜红凯
 * @date: 2022.02.14
 * @since 1.0
 */
public class MyInterceptor implements HandlerInterceptor {
    /**
     * 预处理：处理器方法执行之前执行
     * @param request
     * @param response
     * @param handler
     * @return 如果返回 false ，直接拦截，不执行（阻塞） 如果是true ,放行
     * @throws Exception
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("-----preHandle");
        return true;
    }

    /**
     * 方法执行之后执行的
     *
     * 方法返回值之前执行此方法
     * @param request
     * @param response
     * @param handler
     * @param modelAndView
     * @throws Exception
     */
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("-----postHandle");
    }

    /**
     * 方法执行之后执行
     *
     * 方法返回值之后执行此方法
     * @param request
     * @param response
     * @param handler
     * @param ex
     * @throws Exception
     */
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("-----afterCompletion");
    }
}
